home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / System / ReqToolsLib / Source / reqtools / boopsigads.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-02  |  12.2 KB  |  492 lines

  1.  
  2. /* Boopsi Button */
  3.  
  4. /* The Image structure as used by this class:
  5.  *
  6.  * struct Image {
  7.  *
  8.  * SHORT    LeftEdge;        <---- Offset
  9.  * SHORT    TopEdge;
  10.  *
  11.  * SHORT    Width;           <---- } 4 chars 'Oops' used for identification!
  12.  * SHORT    Height;          <---- }
  13.  *
  14.  * SHORT    Depth;           <---- maintained by boopsi (set to CUSTOMIMAGEDEPTH).
  15.  *
  16.  * USHORT   *ImageData;      <---- only used during init, then points to self!
  17.  *
  18.  * UBYTE    PlanePick;       <---- used for the foreground color
  19.  *
  20.  * UBYTE    PlaneOnOff;      <---- holds ToUpper (underlined char) (after creation!)
  21.  *
  22.  * struct Image *NextImage;  <---- pointer to the next image. Handled by DrawImage().
  23.  * };
  24.  *
  25.  */
  26.  
  27. #include <exec/types.h>
  28. #include <exec/io.h>
  29. #include <exec/memory.h>
  30. #include <exec/execbase.h>
  31. #include <dos/dosextens.h>
  32. #include <utility/tagitem.h>
  33. #include <intuition/intuition.h>
  34. #include <intuition/classes.h>
  35. #include <intuition/classusr.h>
  36. #include <intuition/gadgetclass.h>
  37. #include <intuition/imageclass.h>
  38. #include <intuition/sghooks.h>
  39. #include <graphics/gfxbase.h>
  40. #include <graphics/gfxmacros.h>
  41. #include <libraries/gadtools.h>
  42. #include <graphics/monitor.h>
  43. //#include <devices/audio.h>
  44. #include <proto/graphics.h>
  45. #include <proto/gadtools.h>
  46. #include <proto/exec.h>
  47. #include <proto/layers.h>
  48. #include <proto/utility.h>
  49. #include <proto/console.h>
  50. #include <proto/intuition.h>
  51. #include <proto/dos.h>
  52. #include <string.h>
  53.  
  54. #ifdef _AROS
  55. #include <aros/asmcall.h>
  56. #endif
  57.  
  58. #include "filereq.h"
  59.  
  60. /****************************************************************************************/
  61.  
  62. extern struct Library         *GadToolsBase;
  63. extern struct GfxBase         *GfxBase;
  64. extern struct IntuitionBase     *IntuitionBase;
  65. extern struct Window         *win;
  66. extern struct Screen         *scr;
  67. extern struct ExecBase         *SysBase;
  68. extern struct Device         *ConsoleDevice;
  69.  
  70. extern void ShortDelay (void);
  71. extern APTR STDARGS DofmtArgs (char *, char *,...);
  72.  
  73.  
  74. #ifndef _AROS
  75. extern ULONG ASM myBoopsiDispatch (
  76.     REGPARAM(a0, Class *,),
  77.     REGPARAM(a2, struct Image *,),
  78.     REGPARAM(a1, struct impDraw *,));
  79. #endif
  80.  
  81. extern Class *ButtonImgClass;
  82.  
  83. /****************************************************************************************/
  84.  
  85. /**********
  86. * BUTTONS *
  87. **********/
  88.  
  89. struct Gadget * REGARGS my_CreateButtonGadget (
  90.     struct Gadget *gad,
  91.     ULONG underscorechar,
  92.     struct NewGadget *ng)
  93. {
  94.     struct InitData     idata;
  95.     struct Image     *image;
  96.     char         *label;
  97.  
  98.     label = ng->ng_GadgetText;
  99.     ng->ng_GadgetText = NULL;
  100.     
  101.     if ((gad = myCreateGadget (GENERIC_KIND, gad, ng, TAG_END)))
  102.     {
  103.  
  104.     /* set gadget attributes */
  105.     gad->Flags |= GFLG_GADGIMAGE|GFLG_GADGHIMAGE;
  106.     gad->GadgetType |= GTYP_BOOLGADGET;
  107.     gad->Activation |= GACT_RELVERIFY;
  108.  
  109.     /* set image data */
  110.     idata.idata_Gadget = gad;
  111.     idata.idata_VisualInfo = ng->ng_VisualInfo;
  112.     idata.idata_Label = label;
  113.     idata.idata_TextAttr = ng->ng_TextAttr;
  114.     idata.idata_Underscore = underscorechar;
  115.  
  116.     /* create image */
  117.  
  118.     image = NewObject (ButtonImgClass, NULL, IA_Data, &idata, TAG_END);
  119.  
  120.     gad->GadgetRender = gad->SelectRender = image;
  121.     }
  122.     
  123.     ng->ng_GadgetText = label;
  124.  
  125.     return (gad);
  126. }
  127.  
  128. /****************************************************************************************/
  129.  
  130. static struct Image *IsButtonGad (struct Gadget *gad)
  131. {
  132.     struct Image *im;
  133.  
  134.     if (gad->Flags & (GFLG_GADGIMAGE|GFLG_GADGHIMAGE))
  135.     if ((im = (struct Image *)gad->SelectRender))
  136.         if (im->Depth == CUSTOMIMAGEDEPTH)
  137.         if (*(ULONG *)&im->Width == BUTTON_MAGIC_LONGWORD)
  138.             if (im->ImageData == (UWORD *)im) return (im);
  139.  
  140.     return (NULL);
  141. }
  142.  
  143. /****************************************************************************************/
  144.  
  145. /**********
  146. * STRGADS *
  147. **********/
  148.  
  149. struct CombStringInfo
  150. {
  151.     ULONG             magic;
  152.     struct CombStringInfo     *self;
  153.     struct StringInfo         strinfo;
  154.     struct StringExtend     strextend;
  155.     struct Hook         edithook;
  156. };
  157.  
  158. /****************************************************************************************/
  159.  
  160. #define IEQUALIFIER_SHIFT        (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)
  161.  
  162. /****************************************************************************************/
  163.  
  164. #ifdef _AROS
  165. AROS_UFH3(ULONG, StrEditHookEntry,
  166.     AROS_UFHA(struct Hook *, hook, A0),
  167.     AROS_UFHA(struct SGWork *, sgw, A2),
  168.     AROS_UFHA(ULONG *, msg, A1))
  169. #else
  170. ULONG ASM SAVEDS
  171. StrEditHookEntry (
  172.     REGPARAM(a0, struct Hook *, hook),
  173.     REGPARAM(a2, struct SGWork *, sgw),
  174.     REGPARAM(a1, ULONG *, msg) )
  175. #endif
  176. {
  177.     struct StrGadUserData    *userdata;
  178.     WORD    qual, rawcode;
  179.  
  180.     if( msg[ 0 ] == SGH_KEY )
  181.     {
  182.     rawcode = sgw->IEvent->ie_Code;
  183.     qual = sgw->IEvent->ie_Qualifier;
  184.  
  185. //kprintf("sgsg: editop = %d code = %x  quali = %x\n", sgw->EditOp, rawcode, qual);
  186.  
  187.     if( ( sgw->EditOp == EO_INSERTCHAR ) ||
  188.         ( sgw->EditOp == EO_REPLACECHAR ) ||
  189.         ( sgw->EditOp == EO_SPECIAL ) ||  /* CHECKME: AROS/AMIGAOS: ADDED THIS LINE */
  190.         ( sgw->EditOp == EO_NOOP ) ||  /* CHECKME: AROS/AMIGAOS: ADDED THIS LINE */
  191.         ( sgw->EditOp == EO_ENTER ) ||  /* CHECKME: AROS/AMIGAOS: ADDED THIS LINE */
  192.         ( sgw->EditOp == EO_BADFORMAT ) )
  193.     {
  194. //kprintf("sgsg2\n");
  195.         if( ( qual & IEQUALIFIER_RCOMMAND ) || ( sgw->Code == 27 ) )
  196.         {
  197.         sgw->Actions &= ~( SGA_USE | SGA_BEEP | SGA_REDISPLAY );
  198.         sgw->IEvent->ie_Qualifier &= ~IEQUALIFIER_RCOMMAND;
  199.  
  200.         if( !( qual & IEQUALIFIER_REPEAT ) )
  201.         {
  202.             sgw->Actions |= SGA_REUSE|SGA_END;
  203.             sgw->Code = KEYB_SHORTCUT;
  204.         }
  205.         }
  206.     }
  207.  
  208.     if( ( userdata = ( struct StrGadUserData * ) sgw->Gadget->UserData ) )
  209.     {
  210.         if( userdata->flags & USERFLAG_MATCH_FILE )
  211.         {
  212.         if( sgw->Actions & SGA_USE )
  213.         {
  214.             if( Stricmp( sgw->WorkBuffer, sgw->PrevBuffer ) )
  215.             {
  216.             if( !userdata->fakeimsg.Micros )
  217.             {
  218.                 userdata->fakeimsg.Micros = 1;
  219.                 PutMsg( userdata->msgport, ( struct Message * ) &userdata->fakeimsg );
  220.             }
  221.             }
  222.         }
  223.         }
  224.  
  225.         if( userdata->flags & USERFLAG_UP_DOWN_ARROW )
  226.         {
  227.         if( ( rawcode == RAWKEY_UP ) || ( rawcode == RAWKEY_DOWN ) )
  228.         {
  229.             sgw->Actions &= ~( SGA_USE | SGA_BEEP | SGA_REDISPLAY );
  230.             sgw->Actions |= SGA_REUSE | SGA_END;
  231.             sgw->Code = KEYB_SHORTCUT;
  232.         }
  233.         }
  234.         
  235.     } /* if( ( userdata = ( struct StrGadUserData * ) sgw->Gadget->UserData ) ) */
  236.  
  237.     return( TRUE );
  238.     
  239.     } /* if( msg[ 0 ] == SGH_KEY ) */
  240.  
  241.     return( FALSE );
  242. }
  243.  
  244. /****************************************************************************************/
  245.  
  246. struct Hook stredithook =
  247. {
  248.     { NULL },
  249.     ( HOOKFUNC ) StrEditHookEntry, NULL, ( APTR ) 0xff525421
  250. };
  251.  
  252. /****************************************************************************************/
  253.  
  254. #ifndef GTST_EditHook
  255. #define GTST_EditHook (GT_TagBase+55)
  256. #define GTIN_EditHook GTST_EditHook
  257. #endif
  258.  
  259. /****************************************************************************************/
  260.  
  261. struct Gadget * REGARGS my_CreateIntegerGadget (
  262.     struct Gadget *gad,
  263.     struct NewGadget *newgad,
  264.     int maxchars,
  265.     LONG value,
  266.     ULONG just)
  267. {
  268.     struct Gadget *intgad;
  269.  
  270.     if ((intgad = myCreateGadget (INTEGER_KIND, gad, newgad,
  271.         GTIN_MaxChars, maxchars,
  272.         GTIN_Number, value, STRINGA_Justification, just,
  273.         GTST_EditHook, &stredithook,
  274.     TAG_END)))
  275.         intgad->UserData = NULL;
  276.         
  277.     return (intgad);
  278. }
  279.  
  280. /****************************************************************************************/
  281.  
  282. struct Gadget * REGARGS my_CreateStringGadget (
  283.     struct Gadget *gad,
  284.     struct NewGadget *newgad,
  285.     int maxchars,
  286.     char *string)
  287. {
  288.     struct Gadget *strgad;
  289.  
  290.     if ((strgad = myCreateGadget (STRING_KIND, gad, newgad, GTST_MaxChars, maxchars,
  291.                   GTST_String, string, GTST_EditHook, &stredithook, TAG_END)))
  292.         strgad->UserData = NULL;
  293.  
  294.     return (strgad);
  295. }
  296.  
  297. /****************************************************************************************/
  298.  
  299. void REGARGS my_SetStringGadget (struct Window *win, struct Gadget *gad, char *str)
  300. {
  301.     if (!gad) return;
  302.     
  303.     myGT_SetGadgetAttrs (gad, win, NULL, GTST_String, str, TAG_END);
  304. }
  305.  
  306. /****************************************************************************************/
  307.  
  308. void REGARGS my_SetIntegerGadget (struct Window *win, struct Gadget *gad, long val)
  309. {
  310.     if (!gad) return;
  311.     
  312.     myGT_SetGadgetAttrs (gad, win, NULL, GTIN_Number, val, TAG_END);
  313. }
  314.  
  315. /****************************************************************************************/
  316.  
  317. void REGARGS my_FreeGadgets (struct Gadget *glist)
  318. {
  319.     struct Gadget *gad;
  320.     struct Image  *im;
  321.  
  322.     Forbid();
  323.     for (gad = glist; gad; gad = gad->NextGadget)
  324.     {
  325.     if ((im = IsButtonGad (gad))) DisposeObject (im);
  326.     }
  327.     FreeGadgets (glist);
  328.     Permit();
  329. }
  330.  
  331. /****************************************************************************************/
  332.  
  333. void REGARGS my_SelectGadget (struct Gadget *gad, struct Window *win)
  334. {
  335.     gad->Flags ^= GFLG_SELECTED;
  336.     RefreshGList (gad, win, NULL, 1);
  337. }
  338.  
  339. /****************************************************************************************/
  340.  
  341. void REGARGS my_DownGadget (struct Gadget *gad, UWORD code, struct KeyButtonInfo *info)
  342. {
  343.     my_SelectGadget (gad, info->win);
  344.     ShortDelay();
  345.     info->lastgad = gad;
  346.     info->lastcode = code;
  347. }
  348.  
  349. /****************************************************************************************/
  350.  
  351. #define SHIFT_KEY        0x60
  352.  
  353. /****************************************************************************************/
  354.  
  355. struct Gadget *REGARGS my_GetKeyGadget (UBYTE key, struct Gadget *glist)
  356. {
  357.     struct Gadget *gad;
  358.     struct Image  *im;
  359.     char       underkey;
  360.  
  361.     for (gad = glist; gad; gad = gad->NextGadget)
  362.     {
  363.     if ((im = IsButtonGad (gad)))
  364.         if ((underkey = im->PlaneOnOff))
  365.         if (key == (UBYTE)ToUpper (underkey)) return (gad);
  366.     }
  367.     return (NULL);
  368. }
  369.  
  370. /****************************************************************************************/
  371.  
  372. ULONG REGARGS CheckGadgetKey (int code, int qual, char *key,
  373.                       struct KeyButtonInfo *info)
  374. {
  375.     struct InputEvent     ev;
  376.     struct Gadget     *gad;
  377.     int         upkey = (code & IECODE_UP_PREFIX);
  378.  
  379.     *key = 0;
  380.     if (!(code & ~IECODE_UP_PREFIX)) return (0);
  381.  
  382.     /* Convert RAW to ASCII */
  383.     ev.ie_NextEvent = NULL;
  384.     ev.ie_Class = IECLASS_RAWKEY;
  385.     ev.ie_Code = code;
  386.     /* Ignore alt qualifier */
  387.     ev.ie_Qualifier = qual & ~(IEQUALIFIER_LALT|IEQUALIFIER_RALT);
  388.     RawKeyConvert (&ev, key, 1, NULL);
  389.     *key = ToUpper (*key);
  390.  
  391.     if (!(qual & IEQUALIFIER_REPEAT))
  392.     {
  393.     if (upkey)
  394.     {
  395.         /* Gadget released ? */
  396.         if (code == (info->lastcode | IECODE_UP_PREFIX))
  397.         {
  398.         if (!(info->lastgad->Activation & GACT_TOGGLESELECT))
  399.             my_SelectGadget (info->lastgad, info->win);
  400.         info->lastcode = 0;
  401.         return ((ULONG)info->lastgad->GadgetID);
  402.         
  403.         }
  404.     }
  405.     else
  406.     {
  407.         /* Shift pressed ? */
  408.         if ((code & ~1) == SHIFT_KEY)
  409.         {
  410.         if (info->lastcode)
  411.         {
  412.             my_SelectGadget (info->lastgad, info->win);
  413.             info->lastcode = 0;
  414.         }
  415.         }
  416.         else
  417.         {
  418.         /* No gadget down yet ? */
  419.         if (!info->lastcode)
  420.         {
  421.             /* Gadget down ? */
  422.             if ((gad = my_GetKeyGadget (*key, info->glist)))
  423.             {
  424.             if (!(gad->Flags & GFLG_DISABLED))
  425.                 my_DownGadget (gad, code, info);
  426.                 
  427.             }
  428.             else /* return with keycode in 'key' */
  429.             return (0);
  430.             
  431.         }
  432.         
  433.         }
  434.         
  435.     } /* if (upkey) else ... */
  436.     
  437.     } /* if (!(qual & IEQUALIFIER_REPEAT)) */
  438.     
  439.     *key = 0;
  440.     return (0);
  441. }
  442.  
  443. /****************************************************************************************/
  444.  
  445. /*********
  446. * IMAGES *
  447. *********/
  448.  
  449. /* Read VisualInfo and TextAttr from newgadget structure */
  450. /* Underscore char is always '_' */
  451.  
  452. struct Image * REGARGS my_CreateGadgetLabelImage (
  453.     struct Image *previm,
  454.     struct NewGadget *ng,
  455.     char *label,
  456.     WORD left, WORD top,
  457.     UWORD pen)
  458. {
  459.     struct InitData idata;
  460.  
  461.     if (!previm) return (NULL);
  462.     
  463.     idata.idata_Gadget = NULL;
  464.     idata.idata_Label = label;
  465.     idata.idata_VisualInfo = ng->ng_VisualInfo;
  466.     idata.idata_TextAttr = ng->ng_TextAttr;
  467.     idata.idata_Underscore = '_';
  468.     
  469.     return (previm->NextImage = NewObject (ButtonImgClass, NULL, IA_Data , &idata,
  470.                                      IA_FGPen, pen   , 
  471.                                  IA_Left , left  ,
  472.                                  IA_Top  , top   ,
  473.                                  TAG_END));
  474. }
  475.  
  476. /****************************************************************************************/
  477.  
  478. void REGARGS my_FreeLabelImages (struct Image *images)
  479. {
  480.     struct Image *im;
  481.  
  482.     images = images->NextImage;
  483.     while (images)
  484.     {
  485.     im = images;
  486.     images = images->NextImage;
  487.     DisposeObject (im);
  488.     }
  489. }
  490.  
  491. /****************************************************************************************/
  492.